<template>
  <work-template v-model="ruleForm" v-loading="loading"
                 :flowId="flowId"
                 @closeSelectedTag="closeSelectedTag" :butShow="bool">
    <div slot="form" class="container-div">
      <!--车辆信息  订单信息-->
      <vehicleMessage v-model="ruleForm" :state="isEdit"/>
      <!--申请信息-->
      <applyForMessage v-model="ruleForm" :state="isEdit" v-if="Number(ruleForm.source)=== 1"/>
      <!--处置结果 手动 || 自动-->
      <disposalResult v-model="ruleForm" :state="isEdit"/>
    </div>

  </work-template>
</template>

<script>
import {getDetails} from '@/api/vehicleDisposal/purchaseHandle.js'
export default {
  name: 'PurchaseHandleDetails',
  components: {
    vehicleMessage: () => import('../../components/purchaseHandle/vehicleMessage.vue'),
    applyForMessage: () => import('../../components/purchaseHandle/applyForMessage.vue'),
    disposalResult:() => import('../../components/purchaseHandle/disposalResult.vue'),
  },
  computed: {
    isEdit() {
      if (this.$route.query.type === "edit") {
        return "write";
      }
      if (this.$route.query.type === "view") {
        return "readonly";
      }
    },
    bool() {
      if (this.$route.query.type === "edit") {
        return true;
      }
      if (this.$route.query.type === "view") {
        return false;
      }
    },
    flowId() {
      return this.$route.query?.flowId
    }
  },
  watch: {},
  data() {
    return {
      ruleForm: {}
    };
  },
  created() {
    this.handleDetail()
  },
  mounted() {
  },
  methods: {
    async handleDetail() {
      this.loading = true
      try {
        if(!this.$route.query.id) return
        const res = await getDetails(this.$route.query.id)
        this.ruleForm = res.data
      } catch (e) {
        console.error(e)
      } finally {
        this.loading = false
      }
    },

    closeSelectedTag(view) {
      this.$tab.closePage(view).then(({visitedViews}) => {
        this.$router.push({
          path: "/VehicleDisposal/RentPurchaseTransfer/PurchaseHandleList",
        });
      });
    }
  },
};
</script>

<style lang="scss" scoped>
@import "@/styles/cwgd/container.scss";
</style>


